﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using VIFON.DAL;
using VIFON.BLL;
namespace VIFON
{
    
    public partial class frmBaseMain : Telerik.WinControls.UI.RadForm
    {
        BLUser userbll = new BLUser();
        public frmBaseMain()
        {
            InitializeComponent();           
        }

        private void btnCustomerManage_Click(object sender, EventArgs e)
        {
            if (pnMain.Controls["frmCustomers"] == null)
            {
                pnMain.Controls.Clear();
                frmCustomers objForm = new frmCustomers();
                objForm.TopLevel = false;
                pnMain.Controls.Add(objForm);
                pnMain.AutoScroll = true;
                objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                objForm.Dock = DockStyle.Fill;
                //objForm.Anchor = AnchorStyles.Left;
                objForm.Show();
            }
        }

        private void btnProductManage_Click(object sender, EventArgs e)
        {
            if (pnMain.Controls["frmProducts"] == null)
            {
                pnMain.Controls.Clear();
                frmProducts objForm = new frmProducts();
                objForm.TopLevel = false;
                pnMain.Controls.Add(objForm);
                objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                objForm.Dock = DockStyle.Fill;
                //objForm.Anchor = AnchorStyles.Left;
                objForm.Show();
            }
        }

        private void frmBaseMain_Load(object sender, EventArgs e)
        {
            btnCustomerManage.Enabled = false;
            btnProductManage.Enabled = false;
            radButton1.Enabled = false;
            radButton2.Enabled = false;
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            if (pnMain.Controls["frmBills"] == null)
            {
                pnMain.Controls.Clear();
                frmBills objForm = new frmBills();
                objForm.TopLevel = false;               
                objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                objForm.Dock = DockStyle.Fill;
                //objForm.Anchor = AnchorStyles.Left;
                pnMain.Controls.Add(objForm);
                objForm.Show();    
            }
        }

        private void radButton2_Click(object sender, EventArgs e)
        {
            if (pnMain.Controls["frmCustomerSummary"] == null)
            {
                pnMain.Controls.Clear();
                frmCustomerSummary objForm = new frmCustomerSummary();
                objForm.TopLevel = false;
                pnMain.Controls.Add(objForm);
                objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                objForm.Dock = DockStyle.Fill;
                //objForm.Anchor = AnchorStyles.Left;
                objForm.Show();
            }
        }

        private void btnlogin_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text))
            {
                MessageBox.Show("Nhập Tên đăng nhập hoặc mật khẩu", "Warning");                
            }
            else
            {
                if (userbll.CheckLogin(txtUsername.Text, txtPassword.Text))
                {
                    btnCustomerManage.Enabled = true;
                    btnProductManage.Enabled = true;
                    radButton1.Enabled = true;
                    radButton2.Enabled = true;
                    grb1.Visible = false;
                }
                else
                {
                    MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu");
                    txtUsername.Focus();
                }
            }            
        }

        private void txtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode== Keys.Enter)
            {
                btnlogin.PerformClick();
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
